package com.movecar.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.movecar.R;

/**
 * 发分享选择
 * 
 * @author Zhao.JQ
 *
 */
public class AddShareAlertActivity extends Activity implements OnClickListener {
	private Button add_1, add_2, add_3;
	private RelativeLayout mainRelative;
	private android.view.animation.Animation animation_in, animation_out;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_my_share_button_alert);
		animation_in = AnimationUtils.loadAnimation(this, R.anim.in_left_to_right);
		animation_out = AnimationUtils.loadAnimation(this, R.anim.out_right_to_left);
		initView();
	}

	private void initView() {
		mainRelative = (RelativeLayout) findViewById(R.id.main_relative);
		add_1 = (Button) findViewById(R.id.add_1);
		add_1.setOnClickListener(this);
		add_2 = (Button) findViewById(R.id.add_2);
		add_2.setOnClickListener(this);
		add_3 = (Button) findViewById(R.id.add_3);
		add_3.setOnClickListener(this);
		mainRelative.setVisibility(View.VISIBLE);
		mainRelative.startAnimation(animation_in);
	}

	@Override
	public void onClick(View v) {
		Intent intent;
		switch (v.getId()) {

		case R.id.add_1:
			intent = new Intent().setClass(AddShareAlertActivity.this, AddMyShareActivity.class);
			intent.putExtra("shareFlag", 0);
			startActivityForResult(intent, 0);
			break;
		case R.id.add_2:
			intent = new Intent().setClass(AddShareAlertActivity.this, AddMyShareActivity.class);
			intent.putExtra("shareFlag", 1);
			startActivityForResult(intent, 0);
			break;
		case R.id.add_3:
			intent = new Intent().setClass(AddShareAlertActivity.this, AddMyRedEnvelopesShareActivity.class);
			intent.putExtra("shareFlag", 0);
			startActivityForResult(intent, 0);
			break;
		default:
			break;
		}

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
		if (requestCode == 0) {
			if (resultCode == RESULT_OK) {

				setResult(RESULT_OK, data);
				finish();
			}

		}
	}

	public boolean dispatchKeyEvent(KeyEvent event) {

		if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN
				&& event.getRepeatCount() == 0) {

			mainRelative.startAnimation(animation_out);
			mainRelative.setVisibility(View.GONE);
			new Handler().postDelayed(new Runnable() {
				public void run() {
					
					finish();
				}
			}, 500);

			return false;
		} else {
			return super.dispatchKeyEvent(event);
		}
	}
}
